package com.jbit.springboot04.config;

import com.jbit.springboot04.util.RedisUtil;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

@Configuration
public class RedisConfig {
    @Bean
    public RedisTemplate<String,String> redisTemplate(RedisConnectionFactory connectionFactory){
        RedisTemplate redisTemplate = new RedisTemplate();
        //
        redisTemplate.setKeySerializer(new StringRedisSerializer());
        //数据保存数据库中,不一定保存string类型
        redisTemplate.setValueSerializer(new Jackson2JsonRedisSerializer<Object>(Object.class));
        redisTemplate.setConnectionFactory(connectionFactory);
        return  redisTemplate;
    }
    @Bean
    public RedisUtil redisUtil(){
        return new RedisUtil();
    }
}
